# show percent bar

show_percent_bar <- function(
  percent_value = 0, # 初始值
  times100ed = F, # 是否已经乘过100
  show_value = T, # 是否显示数字还是只显示进度条
  percent_precise = 2, # 进度条显示精度
  total_length = 20, # 进度条长度（字节）
  note = "Processing..." # 提示文字
){
  cat("\014")
  cat(note, "\n", sep = "")
  if(times100ed == F){
    percent_value <- percent_value * 100
  }
  if(show_value){
    cat(round(percent_value, 2), "%\n", sep = "")
  }
  rep_num = round(percent_value * total_length / 100, 0)
  cat("[", paste(rep("=", rep_num), sep = ""),
      paste(rep("_", total_length - rep_num), sep = ""), "]\n", sep = "")
}

# show_percent_bar(percent_value = 1)

# for(i in 1:100000){
#   show_percent_bar(percent_value = i/100000)
# }
